import os,re
from conan import ConanFile
from conan.tools.files import copy
from os.path import join

class CommonSourceCppConan(ConanFile):
    name = "common_source_cpp"
    version = "1.0.3-dev"
    description = "C/C++/C++11公用代码"
    url = "https://gitee.com/l0km/common_source_cpp"
    license = "BSD-2-Clause"
    author = "guyadong 10km0811@sohu.com"
    topics = ("C", "C++", "C++11", "common")

    package_type = "header-library"
    settings = "compiler"
    exports_sources = "*.h", "*.cpp", "*.hpp", "*.hh", "*.c", "LICENSE"
    no_copy_source = True
    
    def package(self):
        copy(self,"*.h", self.source_folder, join(self.package_folder, "include"))
        copy(self,"*.cpp", self.source_folder, join(self.package_folder, "include"))
        copy(self,"*.hpp", self.source_folder, join(self.package_folder, "include"))
        copy(self,"*.hh", self.source_folder, join(self.package_folder, "include"))
        copy(self,"*.c", self.source_folder, join(self.package_folder, "include"))
        copy(self,"LICENSE", self.source_folder, join(self.package_folder, "include"))

    def package_id(self):
        self.info.clear()

    def package_info(self):
        self.cpp_info.bindirs = []
        self.cpp_info.libdirs = []
        if self.settings.compiler == "msvc":
            self.cpp_info.includedirs.append("include/dirent")

    def is_true(self,str):
        return re.match(r'^(?:true|on|1|y(es))?$',str,re.I)

    def configure(self):
		# 指定 common_source_cpp为纯C项目
        if self.is_true(os.getenv("COMMON_SOURCE_CPP_ONLY_C","False")) :
            del self.settings.compiler.libcxx
            del self.settings.compiler.cppstd